<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //字符串填充方法
      console.log('5'.padStart(5, 0));
      console.log('5'.padEnd(3, 'ab'));

      //日期的补0操作
      //当前时间
      let date = new Date();
      //当前月份从0开始计算，需要加一
      let month = date.getMonth() + 1;
      console.log(month);
      //转化为字符串再填补
      console.log(month.toString().padStart(2, 0));
      //startwith 以某个特定字符开头，endwith 以什么结尾
      console.log('abcdeflmn'.startsWith('abc'));
      console.log('abcdeflmn'.endsWith('mn'));
      //trim  取出两端空格
      //trimStart :去除开头空格
      //trimEnd : 去除结尾kongge
      let str = '   a b c  ';
    //   console.log(str.trim());
    console.log(str.trimStart())
    console.log(str.trimEnd())

    //用正侧去除空格
    let str1 = '   a  bc  ';
    //全局匹配空白字符
    let regs = /\s+/g
    console.log(str.replace(regs,''))
    //去左边空格
    let reg1 = /^\s+/g
    console.log(str.replace(reg1,''))
    //去右边空格
    let reg2 = /\s+$/g
    console.log(str.replace(reg2,''))

    </script>
  </body>
</html>
